<%@ page import="com.ld.manageBook.bean.Books" %>
<%@ page import="com.ld.manageBook.service.BookService" %>
<%@ page import="com.ld.manageBook.service.impl.BookServiceImpl" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-02
  Time: 9:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改图书结果</title>
</head>
<body>
<%!
    private BookService bookService = new BookServiceImpl();
%>
<%
    request.setCharacterEncoding("utf-8");
    Books book0 = (Books)(session.getAttribute("currentBook"));
    System.out.println(book0);
    Integer id = book0.getId();
    String name = book0.getName();
	String name0 = name;
	String author = book0.getAuthor();
    double price = book0.getPrice();
    String remarks = book0.getRemarks();
    Integer number = book0.getNumber();
	Integer allnumber = book0.getAllnumber();
    if (!request.getParameter("name").equals("")) {
        name = request.getParameter("name");
    };
    if(!request.getParameter("author").equals("")){
        author = request.getParameter("author");
    }
    if(!request.getParameter("price").equals("")){
        price = Double.parseDouble(request.getParameter("price"));
    };
    if (!request.getParameter("remarks").equals("")) {
        remarks = request.getParameter("remarks");
    };
    if (!request.getParameter("number").equals("")) {
        number = Integer.parseInt(request.getParameter("number"));
    };
    if (!request.getParameter("allnumber").equals("")) {
        allnumber = Integer.parseInt(request.getParameter("allnumber"));
    };
    Books bookByName = bookService.getBookByName(name);
    if(bookByName != null && !bookByName.getName().equals(name0)){
        out.println("该书籍已经存在");
    }else {
        Books book = new Books(id, name, author, price, remarks, number,allnumber);
        int i = bookService.changeBookById(book);
        if (i == 1) {
            out.println("<h1>修改成功</h1>");
        } else {
            out.println("<h1>修改失败,请稍后重试</h1>");
        }
    }
    out.println("<a href='/home/manageBook.jsp'>返回图书管理页</a>");
%>
</body>
</html>
